package com.hmo.appshop;

import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.fragment.app.FragmentManager;
import androidx.leanback.widget.Presenter;

import java.util.List;

public class DetailPresenter extends Presenter {

    private FragmentManager fragmentManager;
    private List<Bitmap> bitmaps;

    public DetailPresenter(FragmentManager fragmentManager, List<Bitmap> bitmaps) {
        this.fragmentManager = fragmentManager;
        this.bitmaps=bitmaps;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.pre_view, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, Object item) {
        ImageView imageView = viewHolder.view.findViewById(R.id.pre_image);
        Bitmap bitmap = (Bitmap) item;
        imageView.setImageBitmap(bitmap);

        viewHolder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Log.d("d","imageview Onclick");
                PreDialog preDialog = new PreDialog();
                //preDialog.setStyle(DialogFragment.STYLE_NORMAL,R.style.PreViewPager);
                preDialog.show(fragmentManager,"predialog");
            }
        });
    }

    @Override
    public void onUnbindViewHolder(ViewHolder viewHolder) {

    }
}
